package com.ruoyi.system.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 使用空间枚举（对应useSpace字段）
 */
@Getter
@AllArgsConstructor
@ApiModel(value = "UseSpaceEnum", description = "使用空间枚举（1=客餐厅，2=主卧，3=次卧，4=阳台，5=厨房，6=主卫，7=次卫，8=入户玄关，9=打拆）")
public enum UseSpaceEnum {

    @ApiModelProperty(value = "客餐厅")
    LIVING_DINING(1, "客餐厅"),

    @ApiModelProperty(value = "主卧")
    MASTER_BEDROOM(2, "主卧"),

    @ApiModelProperty(value = "次卧")
    SECOND_BEDROOM(3, "次卧"),

    @ApiModelProperty(value = "阳台")
    BALCONY(4, "阳台"),

    @ApiModelProperty(value = "厨房")
    KITCHEN(5, "厨房"),

    @ApiModelProperty(value = "主卫")
    MASTER_BATHROOM(6, "主卫"),

    @ApiModelProperty(value = "次卫")
    SECOND_BATHROOM(7, "次卫"),

    @ApiModelProperty(value = "入户玄关")
    ENTRANCE_HALL(8, "入户玄关"),

    @ApiModelProperty(value = "打拆")
    DEMOLITION(9, "打拆"),

    @ApiModelProperty(value = "新建工程")
    NEW_CONSTRUCTION(10, "新建工程"),

    @ApiModelProperty(value = "水电工程")
    WATER_ELECTRICITY(11, "水电工程"),

    @ApiModelProperty(value = "其他费用")
    OTHER_EXPENSES(12, "其他费用");

    @EnumValue
    private final Integer code;

    @JsonValue
    private final String desc;

    /**
     * 根据code获取枚举
     */
    public static UseSpaceEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        return Arrays.stream(values())
                .filter(enumItem -> enumItem.code.equals(code))
                .findFirst()
                .orElse(null);
    }
}